package com.zk.yygh.hosp.controller.api;

import com.zk.yygh.dict_client.service.DictFeignClient;
import com.zk.yygh.hosp.result.Result;
import com.zk.yygh.hosp.service.DepartmentService;
import com.zk.yygh.hosp.service.HospitalService;
import com.zk.yygh.model.hosp.Hospital;
import com.zk.yygh.vo.hosp.DepartmentVo;
import com.zk.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author: 张凯
 * @date: 2022/6/11 - 19:53
 */

@Api("用户端的医院调动接口")
@RestController
@RequestMapping("/api/hosp/site")
public class HospitalSiteController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private DictFeignClient dictFeignClient;

    @ApiOperation(value = "1.根据医院名称进行模糊查询")
    @GetMapping("findHospitalByName/{name}")
    public Result findHospitalByName(@PathVariable("name") String name){
        List<Hospital> hospitalList=hospitalService.findHospitalByName(name);
        return Result.ok(hospitalList);
    }

    @ApiOperation(value ="2.获取分页列表")
    @GetMapping("selectPage/{page}/{limit}")
    public Result selectPage(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit,
                             HospitalQueryVo hospitalQueryVo){
        //调用业务层执行分页查询
        Page<Hospital> pages = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.ok(pages);
    }

    @ApiOperation("3.获取科室列表")
    @GetMapping(value ="getDepartment/{hoscode}")
    public Result getDepartmentByHoscode(@PathVariable("hoscode") String hoscode){
        List<DepartmentVo> schedule = departmentService.getDepartmentTree(hoscode);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "4.根据hoscode获取医院详情")
    @GetMapping("showByHoscode/{hoscode}")
    public Result showHospitalByHoscode(@PathVariable("hoscode") String hoscode){
        HashMap<String, Object> result = hospitalService.getHospitalDetailByHoscode(hoscode);
        return Result.ok(result);
    }

    @ApiOperation(value ="5.根据dictType获取其子一级所属name")
    @GetMapping("getProCity/{dictType}")
    public Result getProCityName(@PathVariable("dictType") String dictType){
        return Result.ok(dictFeignClient.getProCityName(dictType));
    }
}
